﻿Imports OMANE.Common.Model.Interfaces
Imports Actuariat

Public Class MoteurEcheancier
    Implements IV2MoteurEcheancier, IDisposable

    Private m_vision As TypeVision = TypeVision.DEBPER
    Private m_terme As TypeTerme = TypeTerme.TERME

#Region "Constructeur"
    Public Sub New(ByVal Input As IInputMoteurEcheancier)
        m_Inputs = Input
        Initialize()
    End Sub
    Private Sub Initialize()
        AddHandler m_Inputs.AbtMNOChanged, AddressOf Input_Changed
        AddHandler m_Inputs.AbtPerteRevChanged, AddressOf Input_Changed
        AddHandler m_Inputs.AgeFinDCChanged, AddressOf Input_Changed
        AddHandler m_Inputs.AgeFinINCINVChanged, AddressOf Input_Changed
        AddHandler m_Inputs.AgeInitChanged, AddressOf Input_Changed
        AddHandler m_Inputs.CapIniChanged, AddressOf Input_Changed
        AddHandler m_Inputs.LongueurProjChanged, AddressOf Input_Changed
        AddHandler m_Inputs.MajSinDCChanged, AddressOf Input_Changed
        AddHandler m_Inputs.MajSinINCINVChanged, AddressOf Input_Changed
        AddHandler m_Inputs.NbInitAssuresChanged, AddressOf Input_Changed
        AddHandler m_Inputs.SelectionMedicaleChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TableMaintienINCAPINVALChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TableMortChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TarifDCMensChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TarifINCINVMensChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TxComPartenaireChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TxEntreeINCINVChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TxFGChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TxNomMensChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TxRembAntiMensChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TxTaxeINCINVChanged, AddressOf Input_Changed
        AddHandler m_Inputs.TxTechMensChanged, AddressOf Input_Changed
    End Sub
#End Region

#Region "Les Inputs"
    Private m_Inputs As IInputMoteurEcheancier
    Public ReadOnly Property Input As Interfaces.IInputMoteurEcheancier Implements IV2MoteurEcheancier.Input
        Get
            Return m_Inputs
        End Get
    End Property
    Public Sub Input_Changed(ByVal sender As Object, ByVal e As System.EventArgs) Implements IV2MoteurEcheancier.Input_Changed
        'Invalider les calculs et les relancer si le moteur est en mode automatique
    End Sub
#End Region

#Region "Les calculs"
    Public Sub Calculer() Implements IV2MoteurEcheancier.Calculer

        Dim Ech As Double = CalculerEcheanceMensuelle()
        Dim ProjMens As IList(Of IOutputMoteurEcheancierProjMens) = CalculerProjectionMensuelle(Ech)
        Dim ProjAnn As IList(Of IOutputMoteurEcheancierProjAn) = CalculerProjectionAnnuelle(Ech, ProjMens)

        m_Output = New OutputMoteurEcheancier(Ech,
                                                ProjAnn, m_ResultatProjectionAnnuelleDataTable,
                                                ProjMens, m_ResultatProjectionMensuelleDataTable)
        RaiseEvent After_Calculer()
    End Sub
    Public Event After_Calculer() Implements IV2MoteurEcheancier.After_Calculer

#Region "Echéance"
    Private Function CalculerEcheanceMensuelle() As Double
        Return -Pmt(Input.TxNomMens, Input.LongueurProj, Input.CapIni, 0, 0)
    End Function
#End Region

#Region "Projection mensuelle"

    Private Function CalculerProjectionMensuelle_V2(ByVal EcheanceMensuelle As Double) As IList(Of IOutputMoteurEcheancierProjMens)

        Dim ProjMens As New List(Of IOutputMoteurEcheancierProjMens)
        m_ResultatProjectionMensuelleDataTable = New DataTable
        With m_ResultatProjectionMensuelleDataTable.Columns
            'Création de la dataTable contenant les résultats de la projection mensuelle
            Dim m_ResultatProjectionMensuelleDataTable As New DataTable
            .Add("NumMois", GetType(Integer))
            .Add("NumAnnee", GetType(Integer))
            .Add("IndAnneePleine", GetType(Integer))
            .Add("EchDeb", GetType(Double))
            .Add("EchFin", GetType(Double))
            .Add("AgeActuMilPer", GetType(Double))
            .Add("TxMortMilPer", GetType(Double))
            .Add("NbCotisantsDebPer", GetType(Double))
            .Add("nbCotisants", GetType(Double))
            .Add("nbSinDC", GetType(Double))
            .Add("NbSinistresINCAPINVALFinPer", GetType(Double))
            .Add("CotisCommINCINV", GetType(Double))
            .Add("CotisCommDC", GetType(Double))
            .Add("CotisTechINCINV", GetType(Double))
            .Add("CotisTechDC", GetType(Double))
            .Add("SinRegDC", GetType(Double))
            .Add("SinRegINCINV", GetType(Double))
            .Add("projPMRente", GetType(Double))
            .Add("ProjPPRC", GetType(Double))
            .Add("ProjPMDC", GetType(Double))
            .Add("projPMINCINV", GetType(Double))
            .Add("ProjCSRDC", GetType(Double))
            .Add("MSR_Vie", GetType(Double))
        End With

        With Input

            Dim selMedic As Double() = .SelectionMedicale.ValeurEnCours
            Dim isSelMedic As Boolean = Not (selMedic Is Nothing)
            Dim NbCotisants_LastPer As Double = .NbInitAssures

            For NumMois As Integer = 1 To .LongueurProj

                Dim newRow As DataRow = m_ResultatProjectionMensuelleDataTable.NewRow

                newRow("NumMois") = NumMois
                newRow("NumAnnee") = Math.Ceiling(NumMois / 12)

                If Fix(NumMois / 12) = NumMois / 12 Then
                    newRow("IndAnneePleine") = 1
                Else
                    newRow("IndAnneePleine") = 0
                End If

                newRow("EchDeb") = Actuariat.CRD(NumMois, .LongueurProj, .CapIni, .TxNomMens, TypeVision.DEBPER, TypeTerme.TERME)
                newRow("EchFin") = Actuariat.CRD(NumMois, .LongueurProj, .CapIni, .TxNomMens, TypeVision.FINPER, TypeTerme.TERME)

                Dim AgeMilMois As Double = AgeMilieuMois(NumMois, .AgeInit)
                newRow("AgeActuMilPer") = AgeMilMois

                Dim TxMortMilPer As Double = MortaliteMilieuMois(AgeMilMois,
                                                             .TableMort.Values,
                                                             selMedic,
                                                             NumMois,
                                                             True)
                newRow("TxMortMilPer") = TxMortMilPer

                newRow("NbCotisantsDebPer") = NbCotisants_LastPer
                newRow("nbCotisants") = Cotisants(NumMois, .NbInitAssures, NbCotisants_LastPer, .TxRembAntiMens, TxMortMilPer)
                NbCotisants_LastPer = newRow("nbCotisants")

                'newRow("NbSinistresINCAPINVALFinPer") = Nb_INCINV(i, 3)
                'newRow("nbSinDC") = projNbSinDC(i)
                'newRow("CotisCommINCINV") = Proj_Cotis_ComINCINV(i)
                'newRow("CotisCommDC") = Proj_Cotis_ComDC(i)
                'newRow("CotisTechINCINV") = proj_Cotis_techINCINV(i)
                'newRow("CotisTechDC") = Proj_Cotis_TechDC(i)
                'newRow("SinRegDC") = proj_sin_DC(i)
                'newRow("SinRegINCINV") = proj_sin_INCINV(i)
                'newRow("projPMRente") = proj_PM_Rente(i)
                'newRow("ProjPPRC") = proj_PPRC(i)
                'newRow("ProjPMDC") = Proj_PM_DC(i)
                'newRow("projPMINCINV") = Proj_PM_INCINV(i)
                'newRow("ProjCSRDC") = projCSR(i)
                'newRow("MSR_Vie") = Proj_MSR_vie(i)
            Next

        End With

    End Function

    Private m_ResultatProjectionMensuelleDataTable As New DataTable
    Private Function CalculerProjectionMensuelle(ByVal EcheanceMensuelle As Double) As IList(Of IOutputMoteurEcheancierProjMens)

        Dim m_TestTime As New PTIC_Util.TestTimeImpl
        m_TestTime.StartTimer(0)

        Dim ProjMens As New List(Of IOutputMoteurEcheancierProjMens)

        m_ResultatProjectionMensuelleDataTable = New DataTable
        With m_ResultatProjectionMensuelleDataTable.Columns
            'Création de la dataTable contenant les résultats de la projection mensuelle
            Dim m_ResultatProjectionMensuelleDataTable As New DataTable
            .Add("NumMois", GetType(Integer))
            .Add("NumAnnee", GetType(Integer))
            .Add("IndAnneePleine", GetType(Integer))
            .Add("EchDeb", GetType(Double))
            .Add("EchFin", GetType(Double))
            .Add("AgeActuMilPer", GetType(Double))
            .Add("TxMortMilPer", GetType(Double))
            .Add("NbCotisantsDebPer", GetType(Double))
            .Add("nbCotisants", GetType(Double))
            .Add("nbSinDC", GetType(Double))
            .Add("NbSinistresINCAPINVALFinPer", GetType(Double))
            .Add("CotisCommINCINV", GetType(Double))
            .Add("CotisCommDC", GetType(Double))
            .Add("CotisTechINCINV", GetType(Double))
            .Add("CotisTechDC", GetType(Double))
            .Add("SinRegDC", GetType(Double))
            .Add("SinRegINCINV", GetType(Double))
            .Add("projPMRente", GetType(Double))
            .Add("ProjPPRC", GetType(Double))
            .Add("ProjPMDC", GetType(Double))
            .Add("projPMINCINV", GetType(Double))
            .Add("ProjCSRDC", GetType(Double))
            .Add("MSR_Vie", GetType(Double))
        End With

        With Input

            Dim selMedic As Double() = .SelectionMedicale.ValeurUnique
            Dim isSelMedic As Boolean = Not (selMedic Is Nothing)

            Dim num_periodes As Integer() = Actuariat.Proj_Num_Periodes(.LongueurProj)
            Dim num_annee As Integer() = Actuariat.Proj_Num_Annee(.LongueurProj)
            Dim ind_anneesPleines As Integer() = Actuariat.Proj_Ind_AnneesPleines(.LongueurProj)

            Dim proj_echeancier_deb As Double() = Actuariat.Proj_Echeancier(.LongueurProj, .CapIni, .TxNomMens, TypeVision.DEBPER, m_terme)
            Dim proj_echeancier_fin As Double() = Actuariat.Proj_Echeancier(.LongueurProj, .CapIni, .TxNomMens, TypeVision.FINPER, m_terme)
            Dim proj_ages As Double() = Actuariat.Proj_Ages(.AgeInit, .LongueurProj)
            Dim proj_txMort As Double() = Actuariat.Proj_Mortalites(proj_ages, .TableMort.Values, selMedic, .LongueurProj, isSelMedic)
            Dim proj_nbCotisants As Double(,) = Actuariat.Proj_Cotisants(.LongueurProj, .NbInitAssures, .TxRembAntiMens, proj_txMort)
            Dim result As Object

            result = Actuariat.Proj_Nb_INCINV( _
                .LongueurProj, _
                .NbInitAssures, _
                .TxEntreeINCINV, _
                proj_ages, _
                proj_nbCotisants, _
                .TableMaintienINCAPINVAL)
            Dim proj_nbINCAPINVAL As Double(,) = result(0)
            Dim proj_evolINCAPINVAL As Double(,) = result(1)

            Dim proj_cotis_ComDC As Double() = Actuariat.Proj_Cotis_ComDC( _
                .LongueurProj, _
                .CapIni, _
                proj_ages, _
                proj_echeancier_deb, _
                proj_echeancier_fin, _
                .TarifDCMens, _
                TypeTarif.CapitalInitial, _
                TypeTerme.TERME, _
                proj_nbCotisants, _
                .AgeFinDC)

            Dim proj_cotis_techDC As Double() = Actuariat.Proj_Cotis_TechDC( _
                .LongueurProj, _
                proj_cotis_ComDC, _
                .TxFG, _
                .TxComPartenaire)
            Dim proj_cotis_comINCINV As Double() = Actuariat.Proj_Cotis_ComINCINV( _
                .LongueurProj, _
                .CapIni, _
                proj_ages, _
                proj_echeancier_deb, _
                proj_echeancier_fin, _
                .TarifINCINVMens, _
                TypeTarif.CapitalInitial, _
                TypeTerme.TERME, _
                proj_nbCotisants, _
                .AgeFinINCINV)
            Dim proj_cotis_techINCINV As Double() = Actuariat.proj_Cotis_techINCINV( _
                .LongueurProj, _
                proj_cotis_comINCINV, _
                .TxFG, _
                .TxComPartenaire, _
                .TxTaxeINCINV)



            Dim projNbSinDC As Double() = Actuariat.Proj_NbSinDC( _
                .LongueurProj, _
                proj_ages, _
                .AgeFinDC, _
                proj_nbCotisants, _
                proj_txMort)

            Dim proj_sin_DC As Double() = Actuariat.Proj_sin_regDC( _
                .LongueurProj, _
                proj_ages, _
                .AgeFinDC, _
                proj_nbCotisants, _
                proj_txMort, _
                proj_echeancier_deb, _
                .MajSinDC)
            Dim proj_sin_INCINV As Double() = Actuariat.Proj_sin_regINCINV( _
                .LongueurProj, _
                proj_ages, _
                .AgeFinINCINV, _
                proj_nbINCAPINVAL, _
                EcheanceMensuelle, _
                .AbtMNO, _
                .AbtPerteRev, _
                .MajSinINCINV)

            'm_TestTime.StartTimer(1)
            '**************************************************
            'Projection de la PM de Rente
            Dim proj_PM_Rente As Double() = Actuariat.Proj_prov_rente( _
                .LongueurProj, _
                proj_evolINCAPINVAL, _
                proj_nbINCAPINVAL, _
                proj_txMort, _
                .TxRembAntiMens, _
                EcheanceMensuelle, _
                .TxTechMens, _
                .CapIni, _
                .TarifINCINVMens, _
                .TxFG, _
                .TxComPartenaire, _
                .TxTaxeINCINV, _
                .AbtMNO, _
                .AbtPerteRev, _
                .MajSinINCINV)
            'Dim proj_PM_Rente As Double() = ({0.0, 1.1})
            'm_TestTime.StartTimer(2)

            Dim proj_PPRC As Double() = Actuariat.Proj_prov_PPRC( _
                .LongueurProj, _
                proj_evolINCAPINVAL, _
                proj_nbINCAPINVAL, _
                proj_txMort, _
                .TxRembAntiMens, _
                EcheanceMensuelle, _
               .TxTechMens, _
                .CapIni, _
                .TarifINCINVMens, _
                .TxFG, _
                .TxComPartenaire, _
                .TxTaxeINCINV, _
                .AbtMNO, _
                .AbtPerteRev, _
                .MajSinINCINV)
            'Dim proj_PPRC As Double() = ({0.0, 1.1})
            '**************************************************
            'm_TestTime.StartTimer(0)


            Dim proj_PM_DC As Double() = Actuariat.Proj_PM_DC( _
                .LongueurProj, _
                proj_cotis_techDC, _
                proj_sin_DC, _
               .TxTechMens)
            Dim proj_PM_INCINV As Double() = Actuariat.Proj_PM_INCINV( _
               .LongueurProj, _
                proj_cotis_techINCINV, _
                proj_sin_INCINV, _
                .TxTechMens)

            Dim projCSR As Double() = Actuariat.Proj_CSR_DC( _
                .LongueurProj, _
                proj_echeancier_fin, _
                proj_nbCotisants)

            Dim proj_MSR_Vie As Double() = Actuariat.Proj_MSR_vie(.LongueurProj, projCSR)

            For i As Integer = 0 To .LongueurProj - 1

                'Mise à jour de la DataTable
                Dim newRow As DataRow = m_ResultatProjectionMensuelleDataTable.NewRow
                newRow("NumMois") = num_periodes(i)
                newRow("NumAnnee") = num_annee(i)
                newRow("IndAnneePleine") = ind_anneesPleines(i)
                newRow("EchDeb") = proj_echeancier_deb(i)
                newRow("EchFin") = proj_echeancier_fin(i)
                newRow("AgeActuMilPer") = proj_ages(i)
                newRow("TxMortMilPer") = proj_txMort(i)
                newRow("NbCotisantsDebPer") = proj_nbCotisants(i, 0)
                newRow("nbCotisants") = proj_nbCotisants(i, 1)
                newRow("NbSinistresINCAPINVALFinPer") = proj_nbINCAPINVAL(i, 3)
                newRow("nbSinDC") = projNbSinDC(i)
                newRow("CotisCommINCINV") = proj_cotis_comINCINV(i)
                newRow("CotisCommDC") = proj_cotis_ComDC(i)
                newRow("CotisTechINCINV") = proj_cotis_techINCINV(i)
                newRow("CotisTechDC") = proj_cotis_techDC(i)
                newRow("SinRegDC") = proj_sin_DC(i)
                newRow("SinRegINCINV") = proj_sin_INCINV(i)
                newRow("projPMRente") = proj_PM_Rente(i)
                newRow("ProjPPRC") = proj_PPRC(i)
                newRow("ProjPMDC") = proj_PM_DC(i)
                newRow("projPMINCINV") = proj_PM_INCINV(i)
                newRow("ProjCSRDC") = projCSR(i)
                newRow("MSR_Vie") = proj_MSR_Vie(i)
                m_ResultatProjectionMensuelleDataTable.Rows.Add(newRow)

                'Mise à jour de l'objet fortement typé stockant les résultats
                ProjMens.Add(
                    New OutputMoteurEcheancierProjMens(
                        NumMois:=num_periodes(i), _
                        NumAnnee:=num_annee(i), _
                        IndAnneePleine:=ind_anneesPleines(i), _
                        EchDeb:=proj_echeancier_deb(i), _
                        EchFin:=proj_echeancier_fin(i), _
                        AgeActuMilPer:=proj_ages(i), _
                        TxMortMilPer:=proj_txMort(i),
                        NbCotisantsDebPer:=proj_nbCotisants(i, 0), _
                        nbCotisants:=proj_nbCotisants(i, 1),
                        NbSinistresINCAPINVALFinPer:=proj_nbINCAPINVAL(i, 3),
                        nbSinDC:=projNbSinDC(i),
                        CotisCommINCINV:=proj_cotis_comINCINV(i),
                        CotisCommDC:=proj_cotis_ComDC(i),
                        CotisTechINCINV:=proj_cotis_techINCINV(i),
                        CotisTechDC:=proj_cotis_techDC(i),
                        SinRegDC:=proj_sin_DC(i),
                        SinRegINCINV:=proj_sin_INCINV(i),
                        projPMRente:=proj_PM_Rente(i),
                        ProjPPRC:=proj_PPRC(i),
                        ProjPMDC:=proj_PM_DC(i),
                        projPMINCINV:=proj_PM_INCINV(i),
                        ProjCSRDC:=projCSR(i),
                        MSR_Vie:=proj_MSR_Vie(i)
                    )
                )
            Next
        End With

        'm_TestTime.StopTimer()

        'MsgBox("Fin du travail d'optimisation" & vbCrLf & _
        '       "% d'exécution en S du traitement 1 : " & m_TestTime.TempsExec(0) / (m_TestTime.TempsExec(0) + m_TestTime.TempsExec(1) + m_TestTime.TempsExec(2) + m_TestTime.TempsExec(3)) & vbCrLf & _
        '       "% d'exécution en S du traitement 2 : " & m_TestTime.TempsExec(1) / (m_TestTime.TempsExec(0) + m_TestTime.TempsExec(1) + m_TestTime.TempsExec(2) + m_TestTime.TempsExec(3)) & vbCrLf & _
        '       "% d'exécution en S du traitement 3 : " & m_TestTime.TempsExec(2) / (m_TestTime.TempsExec(0) + m_TestTime.TempsExec(1) + m_TestTime.TempsExec(2) + m_TestTime.TempsExec(3)) & vbCrLf & _
        '       "% d'exécution en S du traitement 4 : " & m_TestTime.TempsExec(3) / (m_TestTime.TempsExec(0) + m_TestTime.TempsExec(1) + m_TestTime.TempsExec(2) + m_TestTime.TempsExec(3)))

        Return ProjMens
    End Function

#End Region

#Region "Projection annuelle"
    Private m_ResultatProjectionAnnuelleDataTable As New DataTable
    Private Function CalculerProjectionAnnuelle( _
        ByVal EcheanceMensuelle As Double, _
        ByVal ProjectionMensuelle As IList(Of IOutputMoteurEcheancierProjMens)) _
            As IList(Of IOutputMoteurEcheancierProjAn)

        Dim ProjAn As New List(Of IOutputMoteurEcheancierProjAn)
        Dim CotisDC, SinDC, NbSinDC, CotisIT, SinIT, CSRDCfin, PM_DCtheo, PMRente, PPRC, _
            PM_ITtheo, MSR_Vie, nbCotisants, NbSinistresINCAPINVALFinPer As Double
        Dim numAnnee As Integer = 0

        For numMois As Integer = 1 To ProjectionMensuelle.Count
            If Math.Ceiling(numMois / 12) <> numAnnee Then
                If numAnnee <> 0 Then
                    ProjAn.Add(New OutputMoteurEcheancierProjAn(
                               numAnnee, _
                               CSRDCfin, _
                               CotisDC, _
                               SinDC, _
                               PM_DCtheo, _
                               CotisIT, _
                               SinIT, _
                               PMRente, _
                               PPRC, _
                               PM_ITtheo, _
                               MSR_Vie, _
                               nbCotisants, _
                               NbSinistresINCAPINVALFinPer, _
                               NbSinDC))
                End If
                CotisDC = 0
                SinDC = 0
                NbSinDC = 0
                CotisIT = 0
                SinIT = 0
                numAnnee = Math.Ceiling(numMois / 12)
            End If
            If numMois / 12 = numAnnee Then
                CSRDCfin = ProjectionMensuelle(numMois - 1).ProjCSRDC 'resProjectionMensuelle.Rows(numMois - 1)("ProjCSRDC")
                PM_DCtheo = ProjectionMensuelle(numMois - 1).ProjPMDC 'resProjectionMensuelle.Rows(numMois - 1)("ProjPMDC")
                PMRente = ProjectionMensuelle(numMois - 1).projPMRente 'resProjectionMensuelle.Rows(numMois - 1)("projPMRente")
                PPRC = ProjectionMensuelle(numMois - 1).ProjPPRC 'resProjectionMensuelle.Rows(numMois - 1)("ProjPPRC")
                PM_ITtheo = ProjectionMensuelle(numMois - 1).projPMINCINV 'resProjectionMensuelle.Rows(numMois - 1)("projPMINCINV")
                MSR_Vie = ProjectionMensuelle(numMois - 1).MSR_Vie 'resProjectionMensuelle.Rows(numMois - 1)("MSR_Vie")
                nbCotisants = ProjectionMensuelle(numMois - 1).nbCotisants 'resProjectionMensuelle.Rows(numMois - 1)("nbCotisants")
                NbSinistresINCAPINVALFinPer = ProjectionMensuelle(numMois - 1).NbSinistresINCAPINVALFinPer 'resProjectionMensuelle.Rows(numMois - 1)("NbSinistresINCAPINVALFinPer")
            End If
            CotisDC = CotisDC + ProjectionMensuelle(numMois - 1).CotisCommDC 'resProjectionMensuelle.Rows(numMois - 1)("CotisCommDC")
            SinDC = SinDC + ProjectionMensuelle(numMois - 1).SinRegDC 'resProjectionMensuelle.Rows(numMois - 1)("SinRegDC")
            NbSinDC = NbSinDC + ProjectionMensuelle(numMois - 1).nbSinDC 'resProjectionMensuelle.Rows(numMois - 1)("nbSinDC")
            CotisIT = CotisIT + ProjectionMensuelle(numMois - 1).CotisCommINCINV 'resProjectionMensuelle.Rows(numMois - 1)("CotisCommINCINV")
            SinIT = SinIT + ProjectionMensuelle(numMois - 1).SinRegINCINV 'resProjectionMensuelle.Rows(numMois - 1)("SinRegINCINV")
        Next

        ProjAn.Add(New OutputMoteurEcheancierProjAn(
                           numAnnee, _
                           0, _
                           CotisDC, _
                           SinDC, _
                           0, _
                           CotisIT, _
                           SinIT, _
                           0, _
                           0, _
                           0, _
                           0, _
                           0, _
                           0, _
                           NbSinDC))

        'Création et alimentation de la DataTable
        m_ResultatProjectionAnnuelleDataTable = New DataTable

        With m_ResultatProjectionAnnuelleDataTable.Columns
            .Add("numAnnee", GetType(Integer))
            .Add("CSRDCfin", GetType(Double))
            .Add("cotisDC", GetType(Double))
            .Add("sinDC", GetType(Double))
            .Add("PM_DCtheo", GetType(Double))
            .Add("cotisIT", GetType(Double))
            .Add("sinIT", GetType(Double))
            .Add("PM_Rente", GetType(Double))
            .Add("PPRC", GetType(Double))
            .Add("PM_ITtheo", GetType(Double))
            .Add("MSR_Vie", GetType(Double))
            .Add("nbCotisants", GetType(Double))
            .Add("NbSinistresINCAPINVALFinPer", GetType(Double))
            .Add("nbSinDC", GetType(Double))
        End With

        For i As Integer = 0 To ProjAn.Count - 1
            Dim newRow As DataRow = m_ResultatProjectionAnnuelleDataTable.NewRow
            With ProjAn(i)
                newRow("numAnnee") = .numAnnee
                newRow("CSRDCfin") = .CSRDCfin
                newRow("cotisDC") = .cotisDC
                newRow("sinDC") = .sinDC
                newRow("PM_DCtheo") = .PM_DCtheo
                newRow("cotisIT") = .cotisIT
                newRow("sinIT") = .sinIT
                newRow("PM_Rente") = .PM_Rente
                newRow("PPRC") = .PPRC
                newRow("PM_ITtheo") = .PM_ITtheo
                newRow("MSR_Vie") = .MSR_Vie
                newRow("nbCotisants") = .nbCotisants
                newRow("NbSinistresINCAPINVALFinPer") = .NbSinistresINCAPINVALFinPer
                newRow("nbSinDC") = .nbSinDC
            End With
            m_ResultatProjectionAnnuelleDataTable.Rows.Add(newRow)
        Next

        Return ProjAn
    End Function
#End Region

#End Region

#Region "Les Outputs"
    Private m_Output As IOutputMoteurEcheancier
    Public ReadOnly Property Output As IOutputMoteurEcheancier Implements IV2MoteurEcheancier.Output
        Get
            Return m_Output
        End Get
    End Property
#End Region

#Region "IDisposable Support"
    Private disposedValue As Boolean ' Pour détecter les appels redondants

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: supprimez l'état managé (objets managés).
            End If

            ' TODO: libérez les ressources non managées (objets non managés) et substituez la méthode Finalize() ci-dessous.
            ' TODO: définissez les champs volumineux à null.
        End If
        Me.disposedValue = True
    End Sub

    ' TODO: substituez Finalize() uniquement si Dispose(ByVal disposing As Boolean) ci-dessus comporte du code permettant de libérer des ressources non managées.
    'Protected Overrides Sub Finalize()
    '    ' Ne modifiez pas ce code. Ajoutez du code de nettoyage dans Dispose(ByVal disposing As Boolean) ci-dessus.
    '    Dispose(False)
    '    MyBase.Finalize()
    'End Sub

    ' Ce code a été ajouté par Visual Basic pour permettre l'implémentation correcte du modèle pouvant être supprimé.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Ne modifiez pas ce code. Ajoutez du code de nettoyage dans Dispose(ByVal disposing As Boolean) ci-dessus.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class
